package whf.framework.exception.handlers;

import java.util.Map;

import whf.framework.log.Log;
import whf.framework.log.LogFactory;
import whf.framework.mail.entity.SimpleMail;
import whf.framework.mail.service.MailService;
import whf.framework.util.StringUtils;

/**
 * 如果异常发生,向管理员发送邮件通知
 * @author wanghaifeng
 * @create Oct 19, 2006 2:50:49 PM
 * 
 */
public class OccurThenSendMailToAdmin implements ExceptionHandler {
	private static Log log = LogFactory.getLog(OccurThenSendMailToAdmin.class);
	private MailService mailService;
	
	public void setMailService(MailService service){
		this.mailService = service;
	}
	
	/* (non-Javadoc)
	 * @see whf.framework.exception.handlers.ExceptionHandler#handle(java.lang.Throwable)
	 */
	public void handle(Throwable t, Map parameters) throws ExceptionHandleEndException {
		try{
			mailService.send(new SimpleMail("error occurs", StringUtils.getExceptionDetail(t)));
		}catch(Exception e){
			log.error(this, e);
		}
	}

}
